from pygments.lexer import default

from app.exts import db
from sqlalchemy.ext.hybrid import hybrid_property
class CategoriesModel(db.Model):
    __tablename__='categories'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    name=db.Column(db.String(100),nullable=False,unique=True)
    cover=db.Column(db.String(300))
    description=db.Column(db.Text)
    order=db.Column(db.Integer,default=0)
    blogscat=db.relationship("BlogModel",back_populates="categorie")

    @hybrid_property
    def blog_count(self):
        blogs = self.blogscat
        blogs = [b for b in blogs if b.status == 'published' and b.is_deleted == False]
        return len(blogs)  # 内存计数
